import 'package:enterprise_v6_app/app/components/toast_widget.dart';
import 'package:enterprise_v6_app/app/core/values/images.dart';
import 'package:enterprise_v6_app/app/data/entities/application/education/education_base_page_entity.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/education/iface.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';
import 'package:get/get.dart';

class EducationControllerX extends GetxController {
  final productiveList = [
    EducationProductiveBasePage(
      title: '每日一学',
      image: AppImages.icon_every_day_quiz,
      icon: AppImages.icon_base_right_arrow,
    ),
    EducationProductiveBasePage(
      title: '每周一课',
      image: AppImages.icon_every_week_quiz,
      icon: AppImages.icon_base_right_arrow,
    ),
    EducationProductiveBasePage(
      title: '每月一考',
      image: AppImages.icon_every_month_quiz,
      icon: AppImages.icon_base_right_arrow,
    ),
    EducationProductiveBasePage(
      title: '需求调研',
      image: AppImages.icon_research_page_ing,
      icon: AppImages.icon_base_right_arrow,
    ),
    EducationProductiveBasePage(
      title: '培训计划',
      image: AppImages.icon_train_program_view_ing,
      icon: AppImages.icon_base_right_arrow,
    ),
  ];

  void onClickItem(EducationProductiveBasePage e) async {
    switch (e.title) {
      case '每日一学':
        final quizCfg = await EduQuizIface.getEveryDayQuiz();
          if (quizCfg == null) {
            AppToast.showWarning('暂无可完成题目');
            return;
          }
          Get.toNamed(AppRoutes.quizPage, arguments: quizCfg);
        break;
      case '每周一课':
        final item = await EduQuizIface.getEveryWeekQuiz();
        if (item == null || item.isEmpty) {
          AppToast.showWarning('暂无课程');
          return;
        }

        Get.toNamed(AppRoutes.courseDetailPage, arguments: {
          'id': item.first.id,
          'textbookLecturerId': item.first.textbookLecturerId,
          //isDirectory && isQuestion 都为0时（不进入学习 false）
          'isStudy': item.first.isDirectory == 0  ? false : true,
        });
        break;
      case '每月一考':
        final item = await EduQuizIface.getEveryMonthQuiz();
        if (item == null || item.isEmpty) {
          AppToast.showWarning('暂无考试');
          return;
        }

        final id = item.firstOrNull?.id;
        if (id == null) {
          AppToast.showWarning('暂无考试');
          return;
        }

        final quiCfg = await EduQuizIface.getQuizById(id, '2');
        if (quiCfg == null) {
          AppToast.showWarning('暂无考试');
          return;
        }

        Get.toNamed(AppRoutes.quizPage, arguments: quiCfg);
        break;
      case '需求调研':
        Get.toNamed(AppRoutes.allIngResearchPage);
        break;
      case '培训计划':
        Get.toNamed(AppRoutes.trainIngProgramView);
        break;
      default:
        break;
    }
  }
}
